// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'babel-polyfill';
import fastclick from 'fastclick';
import Router from 'vue-router';
import Vue from 'vue';
import Vant from 'vant';
// import {
//   Lazyload,
//   NoticeBar,
//   Swipe,
//   SwipeItem,
//   CountDown,
//   DatetimePicker,
//   Popup,
//   SwipeCell
// } from 'vant';

import 'vant/lib/index.css';

// import 'common/weui/weui.less';

import 'common/scss/index.scss';
import $alert from 'base/alert/index';
import $toast from 'base/toast/index';
import MyBread from 'base/myBread/myBread';
import $confirm from 'base/confirm/index';
import loading from 'base/loading/index';
import $helpInfo from 'base/helpInfo/index';
import $picker from 'base/picker/index';
import Axios from 'common/js/axios';
import ModalHelper from 'common/js/moveTouch';
import subConfirm from 'base/subConfirm/subConfirm';
import userLogin from 'base/userLogin/index';

import App from './App';
import store from './store';
import router from './router';

import Calendar from 'vue-mobile-calendar'; // 日期选择器

// 开发时 手机调试工具
// import Vconsole from 'vconsole';
// const vConsole = new Vconsole();
// Vue.use(vConsole)

fastclick.attach(document.body); //解决移动端300ms点击延迟
Vue.config.productionTip = false;// 取消生产提示

// base component
Vue.prototype.$alert = $alert;
Vue.prototype.$toast = $toast;
Vue.prototype.$confirm = $confirm;
Vue.prototype.$helpInfo = $helpInfo;
Vue.prototype.$http = Axios;
Vue.prototype.$picker = $picker;
Vue.prototype.$modalHelper = ModalHelper;
Vue.prototype.$userLogin = userLogin;
Vue.use(loading);
Vue.use(Calendar);

Vue.use(Vant);
// Vue.use(Lazyload, {
//   lazyComponent: true
// });
// Vue.use(NoticeBar);
// Vue.use(Swipe);
// Vue.use(SwipeItem);
// Vue.use(CountDown);
// Vue.use(DatetimePicker);
// Vue.use(Popup);
// Vue.use(SwipeCell);

// 全局自定义组件
Vue.component(MyBread.name, MyBread);
Vue.component(subConfirm.name, subConfirm);


Router.prototype.goBack = function(num) {
  this.isBack = true;
  const _num = num || -1;
  window.history.back(_num);
  return false;
};

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App),
  mounted() {
    // for ios
    document.body.addEventListener('touchstart', () => { });
  }
});
/**
 * 路由配置实现：document.title 由路由meta来决定
 * 帮助按钮设置，路由不为首页，bar显示
 */
router.afterEach(to => {
  // 跳转完成之后，修改document.title
  // document.title = to.meta.title;
  document.title = '';
  // 默认帮助按钮不显示，需要显示在路由组件单独设置
  store.commit('SET_VISIBLE_HELP', false);
  // 首页不显示 bar
  if(to.meta.leavel){
    store.commit('SET_VISIBLE_ALL', false);
  }else{
    store.commit('SET_VISIBLE_ALL', true);
  }
});
